package com.xcity.game.combat.unit.impl;

import java.util.Arrays;
import java.util.List;

import com.xcity.db.entity.Employee;
import com.xcity.game.combat.AbstractCombatUnit;
import com.xcity.game.combat.CombatTeam;
import com.xcity.game.combat.attr.CombatAttributeType;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.skill.CombatSkillFactory;
import com.xcity.game.common.ConfirmOperation;
import com.xcity.game.employee.Clazz;
import com.xcity.game.equip.EquipSuit;
import com.xcity.game.equip.suit4.Suit4Factory;
import com.xcity.pomelo.response.EquipmentBagResponse.EquipmentSuit;
import com.xcity.pomelo.response.EquipmentBagResponse.EquipmentSuitEffect;

/**
 * 员工
 * @author yang.li
 *
 */
public class EmployeeCombatUnit extends AbstractCombatUnit<Employee> {

	public EmployeeCombatUnit(CombatTeam team, Employee e) {
		super(team, e);
		setAttributeValue(CombatAttributeType.ATTACK_POWER, e.getAttackPower());
		// 战士取物攻
		setAttributeValue(CombatAttributeType.MAGIC_POWER, e.getTemplate().getClazz() == Clazz.WARRIOR ? e.getAttackPower() : e.getMagicPower());
		setAttributeValue(CombatAttributeType.DEFENSE, e.getDefense());
		setAttributeValue(CombatAttributeType.MAGIC_DEFENSE, e.getMagicDefense());
		setAttributeValue(CombatAttributeType.CRIT, e.getCrit());
		setAttributeValue(CombatAttributeType.AVOID_CRIT, e.getAvoidCrit());
		setAttributeValue(CombatAttributeType.MAX_HP, e.getHp());
		setAttributeValue(CombatAttributeType.HP, e.getHp());
		setAttributeValue(CombatAttributeType.ATTACK_SPEED, e.getAttackSpeed());
		setAttributeValue(CombatAttributeType.CRIT_DAMAGE, e.getCritDamage());
//		setAttributeValue(CombatAttributeType.MAX_MP, 0);
//		setAttributeValue(CombatAttributeType.MP, 0);
		setAttributeValue(CombatAttributeType.DODGE, e.getDodge());
		setAttributeValue(CombatAttributeType.RESIST, e.getResist());
		setAttributeValue(CombatAttributeType.HIT_RATE, e.getHitRate());
		setAttributeValue(CombatAttributeType.MAGIC_HIT_RATE, e.getMagicHitRate());
		
//		List<DefaultSkillV2> skills = e.getSkills();
//		this.skills = new ArrayList<CombatSkill>(2);
//		for (int i = 0; i < skills.size(); i++) {
//			EmployeeSkill skill = skills.get(i);
//			if (skill.getTemplate().isCombatSkill()) {
//				CombatSkill cs = CombatSkillFactory.create(skill.getTemplate());
//				if (cs != null) {
//					this.skills.add(cs);
//				}
//			}
//		}
		CombatSkill cs = CombatSkillFactory.create(e.getSkillManager().getActive());
		this.skills = Arrays.asList(cs);
		setAttributeValue(CombatAttributeType.MAX_MP, cs.getMp());
		// 4件套
		List<EquipmentSuit> suits = e.getEquipSuits();
		for (int i = 0; i < suits.size(); i++) {
			List<EquipmentSuitEffect> effects = suits.get(i).effects;
			for (int j = 0; j < effects.size(); j++) {
				EquipmentSuitEffect eff = effects.get(j);
				if (eff.active == ConfirmOperation.YES && eff.type == EquipSuit.SUIT4.type) {
					suit4Calc = Suit4Factory.create(this, eff.template);
					break;
				}
			}
		}
	}

	@Override
	public int getQualityLvl() {
		return combatable.getQualityLvl();
	}

	@Override
	public Clazz getClazz() {
		return combatable.getTemplate().getClazz();
	}

}
